package rai;

import java.io.IOException;

import rai.service.rep.ListeRepertoires;
import rai.service.transport.RaiSocket;

public class RaiExecCommandeListeRep extends RaiExecCommandeRep {

	private ListeRepertoires lesRepertoires;

	public RaiExecCommandeListeRep(RaiSocket socket, ListeRepertoires lesRepertoires) {
		super(socket);
		this.lesRepertoires = lesRepertoires;
	}

	protected void executerCommande(Commande laCommande) throws IOException,
			ClassNotFoundException {
		super.executerCommande(laCommande);
		String[] liste;
		String identifiant;
		switch (laCommande) {
		case NewRepertoire:
			identifiant = super.socket.readString();
			super.socket.writeBoolean(lesRepertoires
					.creerRepertoire(identifiant));
			break;
		case FindRepertoire:
			identifiant = super.socket.readString();
			super.rep = lesRepertoires.rechercherRepertoire(identifiant);
			super.socket.writeBoolean(super.rep != null);
			break;
		case RemRepertoire:
			identifiant = super.socket.readString();
			boolean estSupprime = lesRepertoires
					.supprimerRepertoire(identifiant);
			super.socket.writeBoolean(estSupprime);
			break;
		case ListeRepertoires:
			liste = lesRepertoires.listerRepertoires();
			super.socket.writeInt(liste.length);
			envoyerListe(liste);
			break;
		case SaveListeRepertoires:
			super.socket.writeBoolean(lesRepertoires.sauverListeRepertoires());
			break;
		case QuitListeRepertoires:
			super.quitter=true;
		}
	}
}
